package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerGasDetectorMapper;
import com.hig.ledger.domain.LedgerGasDetector;
import com.hig.ledger.service.ILedgerGasDetectorService;

/**
 * 可燃气体浓度探测器台账Service业务层处理
 *
 * @author scp
 * @date 2024-09-22
 */
@Service
public class LedgerGasDetectorServiceImpl implements ILedgerGasDetectorService
{
    @Autowired
    private LedgerGasDetectorMapper ledgerGasDetectorMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询可燃气体浓度探测器台账
     *
     * @param id 可燃气体浓度探测器台账ID
     * @return 可燃气体浓度探测器台账
     */
    @Override
    public LedgerGasDetector selectLedgerGasDetectorById(Long id)
    {
        return ledgerGasDetectorMapper.selectLedgerGasDetectorById(id);
    }

    /**
     * 查询可燃气体浓度探测器台账列表
     *
     * @param ledgerGasDetector 可燃气体浓度探测器台账
     * @return 可燃气体浓度探测器台账
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerGasDetector> selectLedgerGasDetectorList(LedgerGasDetector ledgerGasDetector)
    {
        return ledgerGasDetectorMapper.selectLedgerGasDetectorList(ledgerGasDetector);
    }

    /**
     * 新增可燃气体浓度探测器台账
     *
     * @param ledgerGasDetector 可燃气体浓度探测器台账
     * @return 结果
     */
    @Override
    public int insertLedgerGasDetector(LedgerGasDetector ledgerGasDetector)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerGasDetector.setCreateBy(loginUser.getUser().getUserName());
        ledgerGasDetector.setDeptId(loginUser.getUser().getDeptId());
//        long id = ledgerGasDetectorMapper.getNextId();
//        ledgerGasDetector.setId(id);
        ledgerGasDetector.setCreateTime(DateUtils.getNowDate());
        return ledgerGasDetectorMapper.insertLedgerGasDetector(ledgerGasDetector);
    }

    /**
     * 修改可燃气体浓度探测器台账
     *
     * @param ledgerGasDetector 可燃气体浓度探测器台账
     * @return 结果
     */
    @Override
    public int updateLedgerGasDetector(LedgerGasDetector ledgerGasDetector)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerGasDetector.setUpdateBy(loginUser.getUser().getUserName());
        ledgerGasDetector.setUpdateTime(DateUtils.getNowDate());
        return ledgerGasDetectorMapper.updateLedgerGasDetector(ledgerGasDetector);
    }

    /**
     * 批量删除可燃气体浓度探测器台账
     *
     * @param ids 需要删除的可燃气体浓度探测器台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerGasDetectorByIds(Long[] ids)
    {
        return ledgerGasDetectorMapper.deleteLedgerGasDetectorByIds(ids);
    }

    /**
     * 删除可燃气体浓度探测器台账信息
     *
     * @param id 可燃气体浓度探测器台账ID
     * @return 结果
     */
    @Override
    public int deleteLedgerGasDetectorById(Long id)
    {
        return ledgerGasDetectorMapper.deleteLedgerGasDetectorById(id);
    }
}
